import time

from common.Utils import FSDriver
from selenium.webdriver.common.by import By


# 我的帖子
class Myposttest:
    url = ""
    driver = ""

    def __init__(self):
        self.url = "http://127.0.0.1:58080/index.html"
        self.driver = FSDriver.driver
        self.driver.get(self.url)
        self.driver.implicitly_wait(5)

    # 帖子入口
    def post_entry(self):
        # 进入个人帖子
        self.driver.find_element(By.CSS_SELECTOR, '#index_nav_avatar').click()
        self.driver.find_element(By.CSS_SELECTOR, '#index_user_profile').click()
        assert self.driver.find_element(By.CSS_SELECTOR, '#bit-forum-content > div.page-header.d-print-none > div > div')
        assert self.driver.find_element(By.CSS_SELECTOR, '#profile_article_body')
        assert self.driver.find_element(By.CSS_SELECTOR,
                                        '#bit-forum-content > div.page-body > div > div > div.col-lg-4 > div > div > div > div > h2').text == '个人介绍'

    # 帖子详情
    def post_detail(self):
        self.post_entry()

        val = self.driver.find_element(By.CSS_SELECTOR, '#profile_articleCount').text
        # 有帖子
        if val:
            self.driver.find_element(By.CSS_SELECTOR,
                                     '#profile_article_body > li:nth-child(1) > div.card.timeline-event-card > div > div > div > div > div.text-truncate > a > strong').click()
            self.driver.find_element(By.CSS_SELECTOR,
                                     '#bit-forum-content > div.page-header.d-print-none > div > div.col-auto.d-none.d-md-inline > ul')

            # 点赞
            self.driver.find_element(By.CSS_SELECTOR, '#details_btn_like_count').click()
            # 预期结果 点赞成功
            assert self.driver.find_element(By.CSS_SELECTOR, 'body > div.jq-toast-wrap.bottom-right > div')

            # 定位目标元素
            target_element = self.driver.find_element(By.CSS_SELECTOR, '#details_btn_article_reply')
            # 滚动页面至元素可见
            self.driver.execute_script("arguments[0].scrollIntoView(true);", target_element)
            FSDriver.getscreeshot()
            # 回复空消息  即直接点击回复按钮
            time.sleep(1)
            self.driver.find_element(By.ID, 'details_btn_article_reply').click()
            # 预期结果 提示输入内容
            assert self.driver.find_element(By.CSS_SELECTOR, 'body > div.jq-toast-wrap.bottom-right > div')

    def post_test(self):
        self.post_entry()
        self.post_detail()

















